// -----------------------------------------------------------------------
//  <copyright file="ScopedDictionary.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2022 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://www.dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2022-11-25 18:43</last-date>
// -----------------------------------------------------------------------

using System.Security.Claims;

using DaprPlus.Authorization;
using DaprPlus.Filters;


namespace DaprPlus.Dependency;

/// <summary>
/// 基于Scoped生命周期的数据字典，可用于在Scoped环境中传递数据
/// </summary>
public sealed class ScopedDictionary : ConcurrentDictionary<string, object>, IDisposable
{
    /// <summary>
    /// 获取或设置 对于当前数据资源有操作权限的角色Id集合，用于数据权限判断
    /// </summary>
    public long[] ValidRoleIds { get; set; } = [];

    /// <summary>
    /// 获取或设置 忽略后续数据权限验证的类型
    /// </summary>
    public IList<Type> IgnoreDataAuthTypes { get; set; } = new List<Type>();

    /// <summary>
    /// 获取或设置 当前请求Api资源有效的数据权限过滤组
    /// </summary>
    public Dictionary<string, FilterGroup> DataAuthFilterGroups { get; set; } = new();

    /// <summary>
    /// 获取或设置 当前用户
    /// </summary>
    public ClaimsIdentity? Identity { get; set; }

    /// <summary>释放资源.</summary>
    public void Dispose()
    {
        Identity = null;
        Clear();
    }
}
